/*
 * @Author: yangrongxin
 * @Date: 2021-08-02 17:52:10
 * @LastEditors: yangrongxin
 * @LastEditTime: 2021-09-17 10:16:39
 */
import { useState } from 'react';
import { useDidShow } from '@tarojs/taro';
import { STORAGE_TYPE } from '@/const/dataDictionary';
import { getItemSync } from '@/utils/storage';
import { isLoginFn } from '@/utils/common';
import { TeamAdminPage, TeamPage } from './components/index';
import { getCurrentTeamAdmin } from './service';

const Team = () => {
  // 1 是团长 2 不是团长
  const teamMainUser = getItemSync(STORAGE_TYPE.TEAMMAINUSER);

  const [isTeamAdmin, setIsTeamAdmin] = useState(teamMainUser);

  // 当前用户的登录状态
  const isLogin = isLoginFn();

  useDidShow(() => {
    if (isLogin)
      getCurrentTeamAdmin().then((res: any) => {
        setIsTeamAdmin(res.teamMainUser || 2);
      });
  });

  console.log('isTeamAdmin', teamMainUser);

  if (isTeamAdmin === 1 && isLogin) {
    return <TeamAdminPage />;
  }
  return <TeamPage isLogin={isLogin} />;
};

export default Team;
